package font_display;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

//VS4E -- DO NOT REMOVE THIS LINE!
public class FontDisplay extends JFrame {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel0;
	private JTextArea txaNotes;
	private JScrollPane jScrollPane0;
	private JRadioButton radBoid;
	private JCheckBox chkItalic;
	private JPanel jPanel0;
	private JRadioButton radPlain;
	private JTextField txtMessage;
	private ButtonGroup buttonGroup1;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public FontDisplay() {
		initComponents();
		
		CommondListener listener=new CommondListener();
		radBoid.addActionListener(listener);
		radPlain.addActionListener(listener);
		chkItalic.addActionListener(listener);
	}

	private void initComponents() {
		setPreferredSize(new Dimension(400, 250));
		setLayout(new GroupLayout());
		add(getJLabel0(), new Constraints(new Leading(14, 10, 10), new Leading(12, 12, 12)));
		add(getJScrollPane0(), new Constraints(new Leading(13, 154, 10, 10), new Leading(52, 119, 10, 10)));
		add(getJPanel0(), new Constraints(new Leading(175, 10, 10), new Leading(46, 125, 12, 12)));
		initButtonGroup1();
		setSize(418, 240);
	}

	private void initButtonGroup1() {
		buttonGroup1 = new ButtonGroup();
		buttonGroup1.add(getRadPlain());
		buttonGroup1.add(getJRadioButton1());
	}

	private JTextField getJTextField0() {
		if (txtMessage == null) {
			txtMessage = new JTextField();
		}
		return txtMessage;
	}

	private JRadioButton getRadPlain() {
		if (radPlain == null) {
			radPlain = new JRadioButton();
			radPlain.setSelected(true);
			radPlain.setText("Plain");
		}
		return radPlain;
	}

	private JPanel getJPanel0() {
		if (jPanel0 == null) {
			jPanel0 = new JPanel();
			jPanel0.setBorder(BorderFactory.createTitledBorder(null, "Fonts", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION,
					new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel0.setLayout(new GroupLayout());
			jPanel0.add(getRadPlain(), new Constraints(new Leading(6, 10, 10), new Leading(11, 10, 10)));
			jPanel0.add(getJRadioButton1(), new Constraints(new Leading(123, 10, 10), new Leading(14, 10, 10)));
			jPanel0.add(getJCheckBox0(), new Constraints(new Leading(63, 8, 8), new Leading(35, 8, 8)));
			jPanel0.add(getJTextField0(), new Constraints(new Leading(16, 151, 10, 10), new Leading(69, 12, 12)));
		}
		return jPanel0;
	}

	private JCheckBox getJCheckBox0() {
		if (chkItalic == null) {
			chkItalic = new JCheckBox();
			chkItalic.setText("Italic");
		}
		return chkItalic;
	}

	private JRadioButton getJRadioButton1() {
		if (radBoid == null) {
			radBoid = new JRadioButton();
			radBoid.setSelected(true);
			radBoid.setText("Bold");
		}
		return radBoid;
	}

	private JScrollPane getJScrollPane0() {
		if (jScrollPane0 == null) {
			jScrollPane0 = new JScrollPane();
			jScrollPane0.setViewportView(getJTextArea0());
		}
		return jScrollPane0;
	}

	private JTextArea getJTextArea0() {
		if (txaNotes == null) {
			txaNotes = new JTextArea();
			txaNotes.setRows(5);
		}
		return txaNotes;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setText("Notes");
		}
		return jLabel0;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}
	
	/**	
	 * 
	 * User functions
	 */
	
	class CommondListener implements ActionListener{
		public void actionPerformed(ActionEvent ae){
			int style=0;
			String strResult="";
			
			if(radPlain.isSelected()){
				style=Font.PLAIN;
				strResult="Plain";
			}else{
				style=Font.BOLD;
				strResult="Bold";
			}
			
			if(chkItalic.isSelected()){
				style=style | Font.ITALIC;
				Font f=new Font("Tahoma", style, 14);
				txaNotes.setFont(f);
				strResult=strResult+" + Italic";
			}else{
				style=style|Font.PLAIN;
				Font f=new Font("Tahoma",style,14);
				txaNotes.setFont(f);
			}
			txtMessage.setText(strResult);
		}
	}

	/**
	 * Main entry of the class.
	 * Note: This class is only created so that you can easily preview the result at runtime.
	 * It is not expected to be managed by the designer.
	 * You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				FontDisplay frame = new FontDisplay();
				frame.setDefaultCloseOperation(FontDisplay.EXIT_ON_CLOSE);
				frame.setTitle("FontDisplay");
				frame.getContentPane().setPreferredSize(frame.getSize());
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}

}
